<template>
  <div class="con" :style="`height:${height}px`">
    <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
  </div>
</template>
<script>
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        parent: "pid", // 父级唯一标识
        value: "id", // 唯一标识
        label: "name", // 标签显示
        children: "children", // 子级
      },
      height: window.innerHeight - 60 - 20 - 60 - 58,
    };
  },
  methods: {
    handleNodeClick(data) {
      this.$emit('nodeClick',data)
    },
    getMenu() {
      this.$ajax.get("/admin/getmenutree").then((res) => {
        this.data = res.data;
      });
    },
    getOrgList() {
      this.$ajax.get("/admin/getOrg").then((res) => {
        this.data = res.data;
      });
    },
  },
  //1 组织机构 2 功能菜单
  props: ["treeType"],
  mounted() {
    if (this.treeType == "2") {
      this.getMenu();
    } else {
      this.getOrgList();
    }
  },
  created(){
    if (this.treeType == "2") {
      this.defaultProps['label'] = 'menuname'
      this.defaultProps['value'] = 'pid'
    } 
    if (this.treeType == "1") {
      this.defaultProps['label'] = 'name'
      this.defaultProps['value'] = 'id'
    }
  }
};
</script>
<style lang="less" scoped>
.con {
  overflow: auto;
}
</style>